package com.jdwx.opengl.kotlin

import java.util.*


fun printAll(strings: Collection<String>) {
    for(s in strings) print("$s ")
    println()
}
fun List<String>.getShortWordsTo(shortWords: MutableList<String>, maxLength: Int) {
    this.filterTo(shortWords) { it.length <= maxLength }
    // throwing away the articles
    val articles = setOf("a", "A", "an", "An", "the", "The")
    shortWords -= articles
}
fun df( a:Int, ab:()->Boolean){
}


fun main() {

    val stringList:List<String> = listOf("one", "two", "one")
    printAll(stringList)

    val stringSet = setOf("one", "two", "three")
    printAll(stringSet)

    val words = "A long time ago in a galaxy far far away".split(" ")
    val shortWords = mutableListOf<String>()
    words.getShortWordsTo(shortWords, 3)
    println(shortWords)

    val empty = emptyList<String>()
    println( empty)

    val linkedList = LinkedList<String>(listOf("one", "two", "three"))

    println( linkedList.first )
    println( linkedList.get(2) )

    val presizedSet = HashSet<Int>(32)


    presizedSet.add(60)


    val sourceList = mutableListOf(1, 2, 3)
    val referenceList: List<Int> = sourceList
    sourceList.add(4)
    println(referenceList) // 显示 sourceList 当前状态

    val numbers = listOf("one", "two", "three", "four")
    val longerThan3 = numbers.filter { it.length > 3 }
    println(longerThan3)


    val numbers1 = setOf(1, 2, 3)
    println(numbers1.map { it * 3 })
    println(numbers1.mapIndexed { idx, value -> value * idx })

    val numbers2 = listOf("one", "two", "three", "four")

    var i = 3

    if (i in 1..4) {  // 等同于 1 <= i && i <= 4
        println(i)
    }

    for (i in 4 downTo 1) println(i)


    val numbersSequence = sequenceOf("four", "three", "two", "one")

    println(  numbersSequence.iterator().next() )


    val numbers_xl = listOf("one", "two", "three", "four")
    val numbersSequence_xl = numbers_xl.asSequence()
    println(  numbersSequence_xl.iterator().next() )





}

